import axios from 'axios';
import auth from './auth';
import admin from './admin';
import user from './user';
import role from './role';
import setting from './setting';
import privilege from './privilege';


axios.defaults.baseURL = import.meta.env.VUE_APP_URL;
axios.interceptors.request.use(config => {
    const access_token = '';
    if (access_token) {
        config.headers.Accept = 'application/json';
        config.headers.Authorization = `Bearer ${access_token}`;
    }
    return config;
}, err => {
    return Promise.reject(err);
});


axios.interceptors.response.use(response => {
    return response;
}, error => {
    if (error.response) {
        if (error.response.config.url === axios.defaults.baseURL+'auth/login') {
            return Promise.reject(error);
        }
        switch (error.response.status) {
            case 401:
                /**
                 * 返回 401 清除token信息并跳转到登录页面
                 */
                // store.commit(types.SET_TOKEN);
                this.$router.replace({
                    path: '/Login',
                });
                break;
            default:
                return Promise.reject(error);
        }
    }
});

export default {
    auth,
    admin,
    role,
    privilege,
    user,
    setting,
}